using System;
using System.Globalization;
using System.Windows;
using System.Windows.Interactivity;
namespace Microsoft.Expression.Interactivity.Core
{
	public class GoToStateAction : TargetedTriggerAction<FrameworkElement>
	{
		public static readonly DependencyProperty UseTransitionsProperty = DependencyProperty.Register("UseTransitions", typeof(bool), typeof(GoToStateAction), new PropertyMetadata(true));
		public static readonly DependencyProperty StateNameProperty = DependencyProperty.Register("StateName", typeof(string), typeof(GoToStateAction), new PropertyMetadata(string.Empty));
		public bool UseTransitions
		{
			get
			{
				return (bool)base.GetValue(GoToStateAction.UseTransitionsProperty);
			}
			set
			{
				base.SetValue(GoToStateAction.UseTransitionsProperty, value);
			}
		}
		public string StateName
		{
			get
			{
				return (string)base.GetValue(GoToStateAction.StateNameProperty);
			}
			set
			{
				base.SetValue(GoToStateAction.StateNameProperty, value);
			}
		}
		private FrameworkElement StateTarget
		{
			get;
			set;
		}
		private bool IsTargetObjectSet
		{
			get
			{
				return base.ReadLocalValue(TargetedTriggerAction.TargetObjectProperty) != DependencyProperty.UnsetValue;
			}
		}
		protected override void OnTargetChanged(FrameworkElement oldTarget, FrameworkElement newTarget)
		{
			base.OnTargetChanged(oldTarget, newTarget);
			FrameworkElement frameworkElement = null;
			if (string.IsNullOrEmpty(base.TargetName) && !this.IsTargetObjectSet)
			{
				if (!VisualStateUtilities.TryFindNearestStatefulControl(base.AssociatedObject as FrameworkElement, out frameworkElement) && frameworkElement != null)
				{
					throw new InvalidOperationException(string.Format(CultureInfo.get_CurrentCulture(), ExceptionStringTable.GoToStateActionTargetHasNoStateGroups, new object[]
					{
						frameworkElement.get_Name()
					}));
				}
			}
			else
			{
				frameworkElement = base.Target;
			}
			this.StateTarget = frameworkElement;
		}
		protected override void Invoke(object parameter)
		{
			if (base.AssociatedObject != null)
			{
				this.InvokeImpl(this.StateTarget);
			}
		}
		internal void InvokeImpl(FrameworkElement stateTarget)
		{
			if (stateTarget != null)
			{
				VisualStateUtilities.GoToState(stateTarget, this.StateName, this.UseTransitions);
			}
		}
	}
}
